﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="UserControl_Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"
        language="javascript" charset="gb2312"></script>
        
         <script type="text/javascript">
              var o = $('a[href]');
            o.each(function() {
                var oo = $(this);
                oo.click(function() {
                    alert('aa');
                    $('#s1').empty();
                    $.ajax({
                        type: "GET",
                        url: oo.attr('href'),
                        success: function(msg) {
                            $('#s1').append(msg);
                        }
                    });
                    return false;
                });
            });

            //点击查询按钮
            $('#btnSearch').click(function() {
                $('#s1').empty();
                $.ajax({
                    type: "GET",
                    url: 'GetContactsHandler.ashx?SearchType=' + $('#ddlSearchType option:selected').val() + '&Condition=' + $.trim($('#txtCondition').val()),
                    success: function(msg) {
                        if ($.trim(msg) != '') {
                            $('#s1').append(msg);
                        }
                    }
                });
            });

            //左边双击
            $("#s1").dblclick(function() {
                var alloptions = $("#s1 option");
                var so = $("#s1 option:selected");

                so.get(so.length - 1).index == alloptions.length - 1 ? so.prev().attr("selected", true) : so.next().attr("selected", true);
                if($("#s2").val() == null){
                    $("#s2").append(so);
                }
                if($("#s2").val() !=null){
                    $("#s2 option").each(function(){
                        var o = $(this);
                        if(o.val() == so.val()){
                            
                        }
                        else{
                            $("#s2").append(so);
                        }
                    });
                }
            });
            //右边双击
            $("#s2").dblclick(function() {
                var alloptions = $("#s2 option");
                var so = $("#s2 option:selected");

                so.get(so.length - 1).index == alloptions.length - 1 ? so.prev().attr("selected", true) : so.next().attr("selected", true);
                if($("#s1").val() == null){
                $("#s1").append(so);
                }
                if($("#s1").val() !=null){
                    $("#s1 option").each(function(){
                        var o = $(this);
                        if(o.val() == so.val()){
                            s3.append(so);
                        }
                        else{
                            $("#s1").append(so);
                        }
                    });
                }
            });
            //选中右移
            $("#add").click(function() {
                var alloptions = $("#s1 option");
                if ($("#s1 option").val() != null) {
                    var so = $("#s1 option:selected");
                    if (so.length > 0) {
                        so.get(so.length - 1).index == alloptions.length - 1 ? so.prev().attr("selected", true) : so.next().attr("selected", true);
                        if ($('#s2').val() == null) {
                            $("#s2").append(so);
                        }
                        if ($('#s2').val() != null) {
                            var righto = $("#s2 option");
                            var flag = false;
                            righto.each(function() {
                                if ($(this).val() == so.val()) {
                                    flag = true;
                                    return false;
                                }
                            });
                            if (flag == false) {
                                $("#s2").append(so);
                            }
                        }
                    }

                }
            });
            //选中左移
            $("#remove").click(function() {
                var alloptions = $("#s2 option");
                if (alloptions.val() != null) {
                    var so = $("#s2 option:selected");
                    if (so.length > 0) {
                        so.get(so.length - 1).index == alloptions.length - 1 ? so.prev().attr("selected", true) : so.next().attr("selected", true);
                        if ($('#s1').val() == null) {
                            $("#s1").append(so);
                        }
                        if ($('#s1').val() != null) {
                            var lefto = $('#s1 option');
                            var flag = false;
                            lefto.each(function() { 
                                if ($(this).val() == so.val()) {
                                    flag = true;
                                    $('#s3').append(so);
                                    return false;
                            });
                             if (flag == false) {
                                $("#s1").append(so);
                            }
                        }
                    }
                }
            });
            //全部右移
            $("#addall").click(function() {
                //$("#s2").append($("#s1 option").attr("selected", true));
                if ($("#s1").val() != null) {
                    //$("#s1").get(0).selectedIndex = 0;
                    if ($("#s2").val() == null) {
                        $("#s2").append($("#s1 option"));
                    }
                    if ($("#s2").val() != null) {
                        var flag = false;
                        $("#s1 option").each(function() {
                            var s1o = $(this);
                            $("#s2 option").each(function() {
                                s2o = $(this);
                                if (s1o.val() == s2o.val()) {
                                    flag = true;
                                    return false;
                                }
                            });
                            if (flag == false) {
                                $("#s2").append(s1o);
                            }
                        });
                    }
                }
            });
            //全部左移
            $("#removeall").click(function() {
                if ($("#s2").val() != null) {
                    if($("#s1").val() == null){
                        $("#s1").append($("#s2 option"));
                    }
                    if ($("#s1").val() != null) {
                        var flag = false;
                        $("#s2 option").each(function() {
                            var s2o = $(this);
                            $("#s1 option").each(function() {
                                s1o = $(this);
                                if (s1o.val() == s2o.val()) {
                                    flag = true;
                                     $("#s3").append(s2o);
                                    return false;
                                }
                            });
                            if (flag == false) {
                                $("#s1").append(s2o);
                            }
                        });
                    }
                }
            });
        
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>
